//*************************************************************************//
//*           _____   ____________            ______               __     *//
//*          / /__ \ / ____/ ____/           / ____/___  _________/ /     *//
//*     __  / /__/ // __/ / __/    ______   / /_  / __ \/ ___/ __  /      *//
//*    / /_/ // __// /___/ /___   /_____/  / __/ / /_/ / /  / /_/ /       *//
//*    \____//____/_____/_____/           /_/    \____/_/   \__,_/        *//
//*                                                                       *//
//*     Copyright (c) 2006 Ford Argentina. All Rights Reserved.           *//
//*                                                                       *//
//*************************************************************************//

package ar.com.ford.it.webengine.security.menu;

import javax.servlet.http.HttpServletRequest;
import ar.com.ford.it.webengine.websession.WebSession;
import ar.com.ford.it.webengine.websession.WebSessionHelper;
import ar.com.ford.it.webengine.wslx.WslxUser;
import com.ford.it.logging.ILogger;
import com.ford.it.logging.LogFactory;
import com.ford.it.security.plugins.AbstractAuthorizationProviderFactory;
import com.ford.it.security.plugins.AuthorizationException;
import com.ford.it.security.plugins.AuthorizationProvider;

/**
 * MenuAuthorizationProviderFactory <br>
 * 
 * Factory de AuthorizationProviders para menues. Crea objetos de tipo MenuAuthorizationProviderImplementation. <br><br>
 * 
 * <li> Para poder usarse debe configurarse un servlet de clase <b>com.ford.it.security.plugins.AuthorizationInitServlet</b>
 *      en el archivo <code>web.xml</code>
 * <li> Tambien debe configurarse el archivo <code>/fjf/fjf-security-plugins-config.xml</code>
 * 
 * @author Aji
 */
public class MenuAuthorizationProviderFactory extends AbstractAuthorizationProviderFactory {

    private static final String CLASS_NAME = MenuAuthorizationProviderFactory.class.getName();
    private static final ILogger log = LogFactory.getInstance().getLogger(CLASS_NAME);

    
	/**
	 * Constructor
	 */
    public MenuAuthorizationProviderFactory() {
    }

	/**
	 * @see com.ford.it.security.plugins.AuthorizationProviderFactory#getProvider(HttpServletRequest)
	 */
    public AuthorizationProvider getProvider(HttpServletRequest context)  throws AuthorizationException {
        String METHOD_NAME = "getProvider";
        
        log.entering(CLASS_NAME, METHOD_NAME);

        WebSession webSession = WebSessionHelper.getWebSession(context.getSession());
        if (webSession == null)
        	throw new AuthorizationException("WebSession no encontrada");
        
        WslxUser user = webSession.getUser();
        MenuAuthorizationProviderImpl authProv;
        
        if (user == null) {
            throw new AuthorizationException("WslxUser no encontrado");
        }
        
        authProv = new MenuAuthorizationProviderImpl(user);

        log.exiting(CLASS_NAME, METHOD_NAME);
        return authProv;
    }
    
}